package com.fbt.andon.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbt.andon.domain.Facility;
import com.fbt.andon.service.impl.*;
import com.linkwechat.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.ArrayList;

@RestController
@RequestMapping("/board")
@Api(description = "看板信息")
public class BoardController {
    @Autowired
    private GroupServiceImpl groupService;

    @Autowired
    private WorkerServiceImpl workerService;

    @Autowired
    private LineServiceImpl lineService;

    @Autowired
    private FacilityServiceImpl facilityService;

    @Autowired
    private PlantServiceImpl plantService;


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/query")
    @ApiOperation("查询面板统计数")
    public AjaxResult findCount() {
        ArrayList<Integer> board = new ArrayList<Integer>();
        int count = groupService.count(null);
        int count1 = workerService.count(null);
        int count2 = lineService.count(null);
        int count3 = facilityService.count(null);
        int count4 = plantService.count(null);
        board.add(count);
        board.add(count1);
        board.add(count2);
        board.add(count3);
        board.add(count4);
        return AjaxResult.success("查询成功", board);
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/byFacility")
    @ApiOperation("设备异常原因汇总")
    public AjaxResult byFacility() {
        ArrayList<Integer> board = new ArrayList<Integer>();
        QueryWrapper<Facility> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("state", "正常");
        int count1 = facilityService.count(wrapper1);

        QueryWrapper<Facility> wrapper2 = new QueryWrapper<>();
        wrapper2.eq("state", "故障");
        int count2 = facilityService.count(wrapper2);

        QueryWrapper<Facility> wrapper3 = new QueryWrapper<>();
        wrapper3.eq("state", "停机");
        int count3= facilityService.count(wrapper3);

        QueryWrapper<Facility> wrapper4 = new QueryWrapper<>();
        wrapper4.eq("state", "维修");
        int count4= facilityService.count(wrapper4);

        board.add(count1);
        board.add(count2);
        board.add(count3);
        board.add(count4);
        return AjaxResult.success("查询成功", board);
    }


}
